package cn.ai.shoes.common.pojo.entity;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

@Schema(description="分页参数")
@Data
public class PageQueryVo implements Serializable {
    private static final Integer PAGE_NO = 1;
    private static final Integer PAGE_SIZE = 10;
    private static final Integer ORDER_BY_DEFAULT = 0;

    /**
     * 每页条数 - 不分页
     *
     * 例如说，导出接口，可以设置 {@link #pageSize} 为 -1 不分页，查询所有数据。
     */
    public static final Integer PAGE_SIZE_NONE = -1;
    //排序
    @Schema(description = "排序字段{0:根据example的字段排序，1:根据耗时排序}")
    @TableField(exist = false)
    private Integer orderBy = ORDER_BY_DEFAULT;
    //开始时间
    @Schema(description = "开始时间")
    @TableField(exist = false)
    private LocalDateTime begin;
    @Schema(description = "结束时间")
    @TableField(exist = false)
    private LocalDateTime end;

    @Schema(description = "页码，从 1 开始", requiredMode = Schema.RequiredMode.REQUIRED,example = "1")
    @NotNull(message = "页码不能为空")
    @Min(value = 1, message = "页码最小值为 1")
    @TableField(exist = false)
    private Integer pageNum = PAGE_NO;

    @Schema(description = "每页条数，最大值为 100", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
    @NotNull(message = "每页条数不能为空")
    @Min(value = 1, message = "每页条数最小值为 1")
    @Max(value = 100, message = "每页条数最大值为 100")
    @TableField(exist = false)
    private Integer pageSize = PAGE_SIZE;

    // 自定义 setter 方法，确保 pageNum 不为 null
    public void setPageNum(Integer pageNum) {
        this.pageNum = ObjectUtil.isNotEmpty(pageNum) ? pageNum : PAGE_NO;
    }

    // 自定义 setter 方法，确保 pageSize 不为 null
    public void setPageSize(Integer pageSize) {
        this.pageSize =ObjectUtil.isNotEmpty(pageSize) ? pageSize : PAGE_SIZE;
    }

    // 自定义 setter 方法，确保 orderBy 不为 null
    public void setOrderBy(Integer orderBy) {
        this.orderBy = ObjectUtil.isNotEmpty(orderBy) ? orderBy : ORDER_BY_DEFAULT;
    }
}
